#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
double t,n,m,l,maxv;
set<int>s;
vector<int>d;
vector<int>v;
vector<int>a;
vector<int>p;
int main()
{
    ios::sync_with_stdio(0);
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>t;
    while(t--)
    {
        int cnt=0,pmax=-1;
        cin>>n>>m>>l>>maxv;
        d.resize(n+1);
        v.resize(n+1);
        a.resize(n+1);
        p.resize(m+1);
        for(int i=1;i<=n;i++)
            cin>>d[i]>>v[i]>>a[i];
        for(int i=1;i<=m;i++)
        {
            cin>>p[i];
            pmax=max(pmax,p[i]);
        }
        for(int i=1;i<=n;i++)
            if(v[i]>maxv&&d[i]<=pmax)
                cnt++;
        cout<<cnt<<" ";
        if(cnt==0)
            cout<<m<<endl;
        else
            cout<<m-1<<endl;
    }
    return 0;
}
